package org.jackysoft.entity;


import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

import org.apache.struts2.json.annotations.JSON;
import org.jackysoft.entity.Department;
import org.jackysoft.entity.User;
import org.jackysoft.report.visitor.LocalMonthVisitor;
import org.jackysoft.report.visitor.TotalProductionValueVisitor;
import org.joda.time.DateTime;



/**
 * @author Administrator 军品产量月快报
 */
@Entity
@org.hibernate.annotations.Entity(
		dynamicUpdate=true,
		dynamicInsert=true)
public class ArmMonthProductReporter extends AbstractReporter {

	/**
	 * 
	 */
	private static final long serialVersionUID = -9212199125677440084L;
	private ArmMonthProductReporter lastMonthReporter;
    private Double freshValue;
	/**
	 * 
	 */
	public ArmMonthProductReporter() {
		
	}
	

	public ArmMonthProductReporter(String id, String leader,
			String reportMakerLocalName, Department unitName,
			String dateString, String remark, DateTime timestamp) {
		super(id, leader, reportMakerLocalName, unitName, dateString, remark, timestamp);		
	}

	
	public ArmMonthProductReporter(String id, String title,
			DateTime createDate, DateTime updateDate, User maker,
			Department department) {
		super(id, title, createDate, updateDate, maker, department);		
	}


	/**
	 * @return 本月产值
	 */
	@Transient@JSON(serialize=false)
	public Double getLocalMonthValue() throws Exception {
		LocalMonthVisitor visitor = new LocalMonthVisitor();
		for (ArmItem item : this.getArmItems()){
			  item.accetp(visitor);
		}		
		

		return visitor.getValue();
	}

	/**
	 * @return 本月总产值
	 */
	@Transient@JSON(serialize=false)
	public Double getLocalMonthTotalValue() {
		TotalProductionValueVisitor vistor = new TotalProductionValueVisitor();
		for (ArmItem item : this.getArmItems())
			item.accetp(vistor);

		return vistor.getValue();
	}

	/**
	 * @return 累计总产值 = 本月完成+上月累计
	 */
	@Transient@JSON(serialize=false)
	public Double getTotalCumulateValue() {

		LocalMonthVisitor visitor = new LocalMonthVisitor();
		ArmMonthProductReporter last = getLastMonthReporter();
		for (ArmItem item : this.getArmItems())
			visitor.visite(item);
	   
		Double tcv = visitor.getValue() + this.getLastCulumateValue();
		return last == null ? tcv : (tcv + last.getTotalCumulateValue());
	
	}
	
	
	/**
	 * @return the lastMonthReporter
	 */
	@JSON(serialize=false)
	@ManyToOne
	public ArmMonthProductReporter getLastMonthReporter() {
		return lastMonthReporter;
	}

	/**
	 * @param lastMonthReporter
	 *            the lastMonthReporter to set
	 */
	public void setLastMonthReporter(ArmMonthProductReporter lastMonthReporter) {
		this.lastMonthReporter = lastMonthReporter;
	}


	public Double getFreshValue() {
		return freshValue;
	}


	public void setFreshValue(Double freshValue) {
		this.freshValue = freshValue;
	}
	

}
